//
//  HLBespokeView.m
//  NewKY
//
//  Created by 罗浩林 on 16/11/13.
//  Copyright © 2016年 Dee. All rights reserved.
//

#import "HLBespokeView.h"
#import <Masonry.h>
#import "UIColor+CZAddition.h"
#import "NKMainNavigation.h"
#import "HLtreatView.h"
#import "HLWayView.h"
#import "HLSyndromeView.h"
#import "HLDisagnoseView.h"

@interface HLBespokeView ()

@property (nonatomic,strong) HLWayView *wayView;

@property (nonatomic,strong) UILabel *numLabel;

@property (nonatomic,strong) UILabel *sickTypeLabel;

@property (nonatomic,strong) HLSyndromeView *syndromeView;

@property (nonatomic,strong) HLDisagnoseView *diagnoseView;

@property (nonatomic,strong) HLtreatView *treatView;

@property (nonatomic,assign) BOOL select;


@property (nonatomic,strong) UIButton  *applicantBtn;

@end


@implementation HLBespokeView

-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        [self setupUI];
        
    }
    return self;
}

#pragma mark - 界面搭建

/**
 搭建界面
 */
-(void)setupUI{
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(passAction:) name:@"passValue" object:nil];
    
    self.backgroundColor =[UIColor cz_colorWithHex:0xf5f5f5];
    
    /*---疾病类型Label---*/
    UILabel * sickTypeLabel = [UILabel new];
    
    sickTypeLabel.text = @"疾病类型:肿瘤疾病";
    sickTypeLabel.font = [UIFont systemFontOfSize:16];
    
    [self addSubview:sickTypeLabel];
    
    self.sickTypeLabel = sickTypeLabel;
    
    /*---疾病细分View---*/
    self.sickCategoryView= [[NSBundle mainBundle]loadNibNamed:@"sickCategoryView" owner:nil options:nil].lastObject;
    
    self.sickCategoryView.layer.cornerRadius = 3;
    self.sickCategoryView.backgroundColor = [UIColor whiteColor];
    
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pushsickCategoryVC:)];
    
    [self.sickCategoryView addGestureRecognizer:tap];
    
    [self addSubview:self.sickCategoryView];
    
    /*---并发症View---*/
    self.syndromeView= [[NSBundle mainBundle]loadNibNamed:@"syndromeView" owner:nil options:nil].lastObject;
    
    self.syndromeView.layer.cornerRadius = 3;
    self.syndromeView.backgroundColor = [UIColor whiteColor];
    
    UITapGestureRecognizer * syndromeTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pushsyndromeVC:)];
    
    [self.syndromeView addGestureRecognizer:syndromeTap];
    
    [self addSubview:self.syndromeView];
    
    /*---确诊View---*/
    self.diagnoseView= [[NSBundle mainBundle]loadNibNamed:@"diagnoseView" owner:nil options:nil].lastObject;
    
    self.diagnoseView.layer.cornerRadius = 3;
    self.diagnoseView.backgroundColor = [UIColor whiteColor];
    
    [self addSubview:self.diagnoseView];
    
    /*---治疗View---*/
    self.treatView= [[NSBundle mainBundle]loadNibNamed:@"treatView" owner:nil options:nil].lastObject;
    
    self.treatView.layer.cornerRadius = 3;
    self.treatView.backgroundColor = [UIColor whiteColor];
    
    
    __weak typeof(self) weakSelf = self;
    
    //点击按钮,通过block实现隐藏和显示wayView
    self.treatView.treatBlock = ^(){
        [weakSelf.wayView setHidden:NO];
    };
    
    self.treatView.rightBlock = ^(){
        [weakSelf.wayView setHidden:YES];
    };
    
    [self addSubview:self.treatView];
    
    /*---治疗方式View---*/
    self.wayView= [[NSBundle mainBundle]loadNibNamed:@"wayView" owner:nil options:nil].lastObject;
    
    self.wayView.layer.cornerRadius = 3;
    self.wayView.backgroundColor = [UIColor whiteColor];
    
    UITapGestureRecognizer * wayViewTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pushWayViewVC:)];
    
    [self.wayView addGestureRecognizer:wayViewTap];
    
    [self addSubview:self.wayView];
    
    //默认隐藏这个View
    [self.wayView setHidden:YES];
    
    /*---就诊申请Btn---*/
    UIButton * applicantBtn = [[UIButton alloc]init];
    
    [applicantBtn setEnabled:NO];
    
    applicantBtn.backgroundColor = [UIColor lightGrayColor];
    [applicantBtn setTitle:@"就诊申请" forState:UIControlStateNormal];
    [applicantBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    applicantBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    applicantBtn.layer.cornerRadius = 3;
    [applicantBtn addTarget:self action:@selector(clickapplicantBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    [self addSubview:applicantBtn];
    
    self.applicantBtn = applicantBtn;
    
    /*---图片imgView---*/
    UIImageView * iconView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"HL_doctorCount"]];
    
    [self addSubview:iconView];
    
    /*---数量Label---*/
    UILabel * numLabel = [UILabel new];
    
    numLabel.text = @"0位";
    numLabel.font = [UIFont systemFontOfSize:19];
    numLabel.textColor = [UIColor cz_colorWithHex:0x21c6c5];
    
    [self addSubview:numLabel];
    
    _numLabel = numLabel;
    
    /*---重疾匹配Label---*/
    UILabel * ppLabel = [UILabel new];
    
    ppLabel.text = @"重疾诊所为您匹配到";
    ppLabel.font = [UIFont systemFontOfSize:14];
    ppLabel.textColor = [UIColor cz_colorWithHex:0xcdcdcd];
    
    [self addSubview:ppLabel];
    
    /*---布局---*/
    CGFloat spaceRL = 12;
    CGFloat viewH = 35;
    CGFloat viewTop = 8;
    [sickTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(17);
        make.left.equalTo(self.mas_left).offset(spaceRL);
    }];
    
    [self.sickCategoryView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(sickTypeLabel.mas_bottom).offset(24);
        make.left.equalTo(self).offset(spaceRL);
        make.right.equalTo(self).offset(-spaceRL);
        make.height.mas_equalTo(viewH);
    }];
    
    [self.syndromeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.sickCategoryView.mas_bottom).offset(viewTop);
        make.left.equalTo(self).offset(spaceRL);
        make.right.equalTo(self).offset(-spaceRL);
        make.height.mas_equalTo(viewH);
    }];
    
    [self.diagnoseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.syndromeView.mas_bottom).offset(viewTop);
        make.left.equalTo(self).offset(spaceRL);
        make.right.equalTo(self).offset(-spaceRL);
        make.height.mas_equalTo(viewH);
    }];
    
    [self.treatView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_diagnoseView.mas_bottom).offset(viewTop);
        make.left.equalTo(self).offset(spaceRL);
        make.right.equalTo(self).offset(-spaceRL);
        make.height.mas_equalTo(viewH);
    }];
    
    [_wayView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.treatView.mas_bottom).offset(viewTop);
        make.left.equalTo(self).offset(spaceRL);
        make.right.equalTo(self).offset(-spaceRL);
        make.height.mas_equalTo(viewH);
    }];
    
    [applicantBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self).offset(-19);
        make.left.equalTo(self).offset(spaceRL);
        make.right.equalTo(self).offset(-spaceRL);
        make.height.mas_equalTo(viewH);
    }];
    
    CGFloat iconImgWH = 45;
    [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(applicantBtn.mas_top).offset(-12);
        make.centerX.equalTo(applicantBtn);
        make.size.mas_equalTo(CGSizeMake(iconImgWH, iconImgWH));
    }];
    
    [numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(iconView.mas_top).offset(-13);
        make.centerX.equalTo(iconView);
    }];
    
    [ppLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(numLabel.mas_top).offset(-14);
        make.centerX.equalTo(numLabel);
    }];

}

#pragma mark - 手势监听事件

-(void)pushsickCategoryVC:(UITapGestureRecognizer *)tap{
    
    if (self.sickCategoryBlock) {
        self.sickCategoryBlock();
    }
}

-(void)pushsyndromeVC:(UITapGestureRecognizer *)tap{
    
    if (self.syndromeViewBlock) {
        self.syndromeViewBlock();
    }
    
}

-(void)pushWayViewVC:(UITapGestureRecognizer *)tap{
 
    if (self.wayViewBlock) {
        self.wayViewBlock();
    }
}


-(void)clickapplicantBtn:(UIButton *)sender{
    
    if (self.BtnBlock) {
        self.BtnBlock();
    }
    
}

-(void)passAction:(NSNotification *)noti{
    
    NSNumber * NUM = noti.object;
    
    self.select =NUM.boolValue;
    
    [self.applicantBtn setEnabled:self.select];
    
    [self.applicantBtn setBackgroundColor:[UIColor cz_colorWithHex:0x21c6c5]];
    
}



#pragma mark - set传值

-(void)setSickStr:(NSString *)sickStr{
    
     self.sickCategoryView.text= sickStr;
    
}

-(void)setWayStr:(NSString *)wayStr{
    
    _wayStr = wayStr;
    
    self.wayView.wayText = wayStr;
}

-(void)setDoctorCount:(NSInteger)doctorCount{
    
    _doctorCount = doctorCount;
        
    _numLabel.text = [NSString stringWithFormat:@"%zd位",doctorCount];

    
}

-(void)setSickTypeStr:(NSString *)sickTypeStr{
    
    _sickTypeStr = sickTypeStr;
    
    self.sickTypeLabel.text = [NSString stringWithFormat:@"疾病类型:%@疾病",sickTypeStr];
    
}


-(void)setSyndromeArr:(NSArray *)syndromeArr{
    
    _syndromeArr = syndromeArr;
    
    self.syndromeView.syndromeArr = syndromeArr;
    
}


-(void)setSickSelect:(NSInteger)sickSelect{
    
    _sickSelect = sickSelect;
    
    self.diagnoseView.sickSelect = sickSelect;
    
    self.treatView.sickSelect = sickSelect;
}

@end
